import QtQuick 1.1
//import ShellInvoker 1.0
import "../../../common/lib/kdeadmouseutils-build-desktop"

Rectangle {
  property alias photoModelManager : modelManager
  property alias  picasaUrl : modelManager.picasaUrl
  property alias  sPath : modelManager.sPath
  
  border {width:4;color: activeFocus?'yellow':'white'}
  color : 'black'
  height : 200
  width : 340
  id:mainRect
  
  PhotoModel {
    id : modelManager
    property string picasaUrl
    property string sPath
    
    Component.onCompleted : {
      if(sPath){
	loadLocalModel(sPath);
      }else{
	loadPicasaAlbum(picasaUrl);
      }
    }
    //Component.onCompleted : loadLocalModel('/home/manu/Images');
    //Component.onCompleted : loadPicasaAlbum('https://picasaweb.google.com/data/feed/base/user/112103620701242175348?alt=atom&kind=photo&hl=fr&access=public');
  }
  
  Item {
	id: presentItem
	height:parent.height - 100
	width:parent.width - 100
	anchors.centerIn : parent
	
	function radomInterval(min,max){
	    return min + (max-min)*Math.random();
	}
	
	function perturbe(elt) {
	  elt.x += radomInterval(-30,30);
	  elt.y += radomInterval(-30,30);
	  elt.rotation = radomInterval(-10,10);
	}
	Image{
	      id:img1
	      height:parent.height;width:parent.width
	      fillMode: Image.PreserveAspectFit
	      smooth : true
	      Rectangle{ 
		smooth : true;
		radius : 4
		color:'transparent';
		anchors.centerIn:parent;
		width:parent.paintedWidth;
		height:parent.paintedHeight;
		border{color:'white';width:3}
	      }
	  }
	
	Image{
	      id:img2
	      height:parent.height;width:parent.width
	      fillMode: Image.PreserveAspectFit
	      smooth : true
	      Rectangle{ 
		smooth : true; 
		radius : 4
		color:'transparent';
		anchors.centerIn:parent;
		width:parent.paintedWidth;
		height:parent.paintedHeight;
		border{color:'white';width:3}
	      }
	  }
	  
	Image{
	      id:img3
	      height:parent.height;width:parent.width
	      fillMode: Image.PreserveAspectFit
	      smooth : true
	      Rectangle{ 
		smooth : true; 
		color:'transparent';
		radius : 4
		anchors.centerIn:parent;
		width:parent.paintedWidth;
		height:parent.paintedHeight;
		border{color:'white';width:3}
	      }
	  }  
	
	Image{
	      id:img4
	      height:parent.height;width:parent.width
	      fillMode: Image.PreserveAspectFit
	      smooth : true
	      Rectangle{ 
		smooth : true; 
		color:'transparent';
		anchors.centerIn:parent;
		width:parent.paintedWidth;
		radius : 4
		height:parent.paintedHeight;
		border{color:'white';width:3}
	      }
	  }
	
	Connections {
	    target : modelManager
	    onModelReady : {
		  console.log('images ready');
		  img1.source = modelManager.model.get(0).url;
		  img2.source = modelManager.model.get(1).url;
		  img3.source = modelManager.model.get(2).url;
		  img4.source = modelManager.model.get(3).url;
		  presentItem.perturbe(img1);
		  presentItem.perturbe(img2);
		  presentItem.perturbe(img3);
		  presentItem.perturbe(img4);
	    }
	}
	
    }
}
